{extend name="layout/common_layout" /}
{block name="body"}
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/article/index')}">文章管理</a></li>
            <li class=""><a href="{:url('admin/article/add')}">添加文章</a></li>
            <li class="layui-this">编辑文章</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/article/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属栏目</label>
                        <div class="layui-input-block">
                            <select name="cid" lay-verify="required">
                                {foreach name="category_level_list" item="vo"}
                                <option value="{$vo.id}" {if condition="$article.cid==$vo.id"} selected="selected"{/if}>{neq name="vo.level" value="1"}|{php}for($i=1;$i<$vo['level'];$i++){echo ' ----';}{/php}{/neq} {$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="{$article.title}" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" value="{$article.author}" placeholder="（选填）请输入作者" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-block">
                            <textarea name="keywords" placeholder="（选填）请输入关键字" class="layui-textarea">{$article.keywords}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">简介</label>
                        <div class="layui-input-block">
                            <textarea name="introduction" placeholder="（选填）请输入简介" class="layui-textarea">{$article.introduction}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" lay-verify="content" placeholder="" class="layui-textarea editor-textarea" id="content">{$article.content}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">附件【回复查看下载】</label>
                        <div class="layui-input-block">
                            <textarea name="attar" placeholder="（选填）请输入隐藏附件" class="layui-textarea">{$article.attar}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">缩略图</label>
                        <div class="layui-input-block">
                            <input type="text" name="thumb" value="{$article.thumb}" class="layui-input layui-input-inline" id="thumb">
                            <input type="file" name="file" class="layui-upload-file">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图集</label>
                        <div class="layui-input-block">
                            <button type="button" id="upload-photo-btn" class="layui-btn">上传图集</button>
                            <div id="photo-container">
                                {if condition="!empty($article['photo'])"}
                                {foreach name="$article['photo']" item="vo"}
                                <div class="photo-list">
                                    <input type="text" name="photo[]" value="{$vo}" class="layui-input layui-input-inline">
                                    <button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button>
                                </div>
                                {/foreach}
                                {/if}
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读权限[认证角色]</label>
                        <div class="layui-input-inline">
                            <select name="identity_id">
                                <option value="">完全开放</option>
                                {foreach name="identity_list_info" item="identity"}
                                <option value="{$identity.id}" {if condition="$article['identity_id']==$identity['id']"}selected{/if}>{$identity.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="已审核" {if condition="$article.status==1"} checked="checked"{/if}>
                            <input type="radio" name="status" value="0" title="未审核" {if condition="$article.status==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">置顶</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_top" value="1" title="置顶" {if condition="$article.is_top==1"} checked="checked"{/if}>
                            <input type="radio" name="is_top" value="0" title="未置顶" {if condition="$article.is_top==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="publish_time" value="{$article.publish_time}" class="layui-input datetime">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">奖励积分</label>
                        <div class="layui-input-block">
                            <input type="text" name="offer" value="{$article.offer}" required  lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$article.sort}" required  lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$article.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{/block}
{block name="js"}
<!--<script src="__JS__/kindeditor/kindeditor.config.js"></script>-->
<!--<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>-->
<script src="__JS__/ueditor/ueditor.config.js"></script>
<script src="__JS__/ueditor/ueditor.all.min.js"></script>
{/block}
{block name="script"}
<script>
    //文件上传
    layui.upload({
        url: "/index.php/api/upload/upload",
        type: 'file',
        elem:'#attar',
        success: function (data) {
            if (data.error === 0) {
                document.getElementById('file').value = data.url;
            } else {
                layer.msg(data.message);
            }
        }
    });

    $(function() {
        var ue = UE.getEditor('content'),
            uploadEditor = UE.getEditor('upload-photo-btn'),
            photoListItem,
            uploadImage;

        uploadEditor.ready(function () {
            uploadEditor.setDisabled();
            uploadEditor.hide();
            uploadEditor.addListener('beforeInsertImage', function (t, arg) {
                $.each(arg, function (index, item) {
                    photoListItem = '<div class="photo-list"><input type="text" name="photo[]" value="' + item.src + '" class="layui-input layui-input-inline">';
                    photoListItem += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>';

                    $('#photo-container').append(photoListItem).on('click', '.remove-photo-btn', function () {
                        $(this).parent('.photo-list').remove();
                    });
                });
            });
        });

        $('#upload-photo-btn').on('click', function () {
            uploadImage = uploadEditor.getDialog("insertimage");
            uploadImage.open();
        });
    });

//    $(document).ready(function () {
//        var _kindEditor;
//        KindEditor.ready(function(K) {
//            _kindEditor = K.create('#content', KindEditorOptions);
//
//            K('#upload-photo-btn').click(function () {
//                var photo_list_item = '';
//                _kindEditor.loadPlugin('multiimage', function() {
//                    _kindEditor.plugin.multiImageDialog({
//                        showRemote : false,
//                        imageUrl : K('#photo').val(),
//                        clickFn : function(data) {
//                            $.each(data, function (index, item) {
//                                photo_list_item += '<div class="photo-list"><input type="text" name="photo[]" value="' + item.url + '" class="layui-input layui-input-inline">';
//                                photo_list_item += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>'
//                            });
//                            $('#photo-container').append(photo_list_item);
//                            _kindEditor.hideDialog();
//                        }
//                    });
//                });
//            });
//        });
//
//        $('#photo-container').on('click', '.remove-photo-btn', function () {
//            $(this).parent('.photo-list').remove();
//        });
//    });
</script>
{/block}